-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inline vLLM inference provider to regression tests and fix regressions #662
base: main
Are you sure you want to change the base?
Conversation
Merge changes from main branch
@@ -67,7 +67,9 @@ def sample_tool_definition(): | |||
|
|||
|
|||
class TestInference: | |||
@pytest.mark.asyncio | |||
# Session scope for asyncio because the tests in this class all | |||
# share the same provider instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frreiss can you explain a bit what this change does (or rather not having this causes)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, happy to explain.
The fixtures in llama_stack/providers/tests/inference/fixtures.py
are all tagged with @pytest.fixture(scope="session")
. This tag means that these fixtures are initialized once, then reused for the rest of the test session. Reusing the fixtures this way makes the tests run faster. The fixtures for inline providers need to load models from disk.
The default behavior of the pytest-asyncio
plugin is to spawn a new ayncio event loop for every test case.
The result of these two different scoping policies is that the fixtures are being initialized under one event loop, then the test cases interact with the fixtures from a different event loop (one event loop per test case). This change of event loops happens not to break the existing tests, because the inference providers they exercise are stateless at the asyncio layer.
vLLM is not stateless at the asyncio layer. An idle vLLM instance has an event handler waiting for new inference requests to be added to the current batch. Switching to a different event loop drops this event handler, preventing vLLM's batching mechanism from functioning. When I added the inline vLLM provider to the test cases, the change in event loops caused the inference tests to hang.
Adding @pytest.mark.asyncio(loop_scope="session")
to a test case prevents pytest-asyncio
from switching event loops when running the test case. This change ensures that the asyncio event loop used during the test case is the same as the event loop that was present when any session-scoped fixtures were initialized.
The primary potential downside of scoping the event loop in this way is that, if a misbehaving test case were to leave orphan event handlers, those event handlers could cause errors in later test cases instead of causing an error in the misbehaving test case. This risk seemed acceptable to me.
What does this PR do?
This PR adds the inline vLLM inference provider to the regression tests for inference providers. The PR also fixes some regressions in that inference provider in order to make the tests pass.
Test Plan
Command to run the new tests (from root of project):
Output of the above command after these changes:
The warning about "asyncio_default_fixture_loop_scope" appears to be due to my environment having a newer version of pytest-asyncio.
The warning about a pending task appears to be due to a bug in
vllm.AsyncLLMEngine.shutdown_background_loop()
. It looks like that method returns without stopping a pending task. I will look into that issue separately.Sources
Before submitting
Pull Request section?